﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace GetSystemInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(GetOSName(GetProductType()));
            Console.ReadLine();
        }

        private static string GetOSName(string productType)
        {
            System.OperatingSystem os = System.Environment.OSVersion;
            string osName = "Unknown";

            switch (os.Platform)
            {
                case System.PlatformID.Win32Windows:
                    switch (os.Version.Minor)
                    {
                        case 0:
                            osName = "Windows 95";
                            break;
                        case 10:
                            osName = "Windows 98";
                            break;
                        case 90:
                            osName = "Windows ME";
                            break;
                    }
                    break;
                case System.PlatformID.Win32NT:
                    switch (os.Version.Major)
                    {
                        case 3:
                            osName = "Windws NT 3.51";
                            break;
                        case 4:
                            osName = "Windows NT 4";
                            break;
                        case 5:
                            if (os.Version.Minor == 0) osName = "Windows 2000";
                            else 
                                if (os.Version.Minor == 1) osName = "Windows XP";
                                else 
                                    if (os.Version.Minor == 2) osName = "Windows Server 2003";
                            break;
                        case 6:
                            if (productType == "work")
                            {
                                if (os.Version.Minor == 0) osName = "Windows Vista";
                                else
                                    if (os.Version.Minor == 1) osName = "Windows 7";
                                    else
                                        if (os.Version.Minor == 2) osName = "Windows 8";
                                        else
                                            if (os.Version.Minor == 3) osName = "Windows 8.1";
                            }
                            else
                                if (productType == "server")
                                {
                                    if (os.Version.Minor == 0) osName = "Windows Server 2008";
                                    else
                                        if (os.Version.Minor == 1) osName = "Windows Server 2008 R2";
                                        else
                                            if (os.Version.Minor == 2) osName = "Windows Server 2012";
                                            else
                                                if (os.Version.Minor == 3) osName = "Windows Server 2012 R2";
                                }
                            break;
                    }
                    break;
            }
            return osName + ", " + os.ServicePack.ToString() + ", " + os.Version.ToString();
        }

        static string GetProductType()
        {
            string value = String.Empty;
            string key = @"SYSTEM\CurrentControlSet\Control\ProductOptions";
            using (RegistryKey regKey = Registry.LocalMachine.OpenSubKey(key))
            {
                if (regKey != null)
                {
                    try
                    {
                        switch (regKey.GetValue("ProductType").ToString())
                        {
                            case "WinNT": 
                                value = "work"; 
                                break;
                            case "LanmanNT": 
                                value = "domen"; 
                                break;
                            case "ServerNT": 
                                value = "server"; 
                                break;
                            default: 
                                value = "other"; 
                                break;
                        }
                    }
                    catch (Exception ex)
                    {
                        return ex.Message;
                    }
                    return value;
                }
                else
                    return "не удалось найти указанный ключ";
            }
        }
    }
}
